import { ArchivesList } from '@/services';
import { archivesTS } from '@/types';
import { Effect, Reducer} from 'umi';

export interface ArchivesModelState {
    archivesitem: archivesTS[]
    archivesLength: number
    archivesData: object
}

export interface ArchivesModelType {
    namespace: 'archives';
    state: ArchivesModelState;
    effects: {
        ArchivesList: Effect;
    };
    reducers: {
        save: Reducer<ArchivesModelState>;
    };
}

const ArchivesModel: ArchivesModelType = {
    namespace: 'archives',

    state: {
        //归档列表数据
        archivesitem: [],
        archivesLength: 18,
        archivesData:{}
    },

    effects: {
        // 归档列表
        *ArchivesList({ payload }, { call, put }) {
            const result = yield call(ArchivesList,payload)
            
            if (result.data) {
                yield put({
                    type: 'save',
                    payload: {
                        archivesData: result.data,
                        archivesitem: result.data[2022].January
                    },

                })
            }
          
        },
        
    },
    reducers: {
        save(state, action) {
            return {
                ...state,
                ...action.payload,
            };
        },
    },
};

export default ArchivesModel;